#include "DeadProxyClient.h"
#include "DeadProxyClientEventHandler.h"


EventHandler::EventHandler(EventQueue * Que, wxMutex* EvtMut, wxCondition * EvtCond, void * pClient)
{
    ptrClient = pClient;
    Queue = Que;
    EvtMutex = EvtMut;
    EvtCondition = EvtCond;
}

void* EventHandler::Entry()
{
    while(true)
    {
        if(Queue->GetCount() == 0)
        {
            EvtCondition->Wait();
        } else {
            ClientEvent * evt = Queue->GetEvent();
            ((Client*)ptrClient)->EventParser(evt);
            if(evt->GetID() == CE_DESTROYSELF) //time to finish
            {
                delete evt;
                break;
            }
            delete evt;
        }
    }
    return NULL;
}

void EventHandler::OnExit()
{
    delete Queue;
    delete EvtCondition;
    //delete EvtMutex;
}
